<template>
  <div
    class="modal fade"
    tabindex="-1"
    role="dialog"
    aria-hidden="true"
    :id="id"
  >
    <div class="modal-dialog modal-dialog-centered">
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title">
            <slot name="title"> 新增FD下载 </slot>
          </h4>
          <button
            type="button"
            class="btn-close"
            data-bs-dismiss="modal"
            aria-label="Close"
          ></button>
        </div>
        <div class="modal-body">
          <form role="form" class="form-horizontal">
            <div class="row">
              <label class="control-label col-md-4"> 航空公司 </label>
              <div class="col-md-6">
                <input
                  type="text"
                  class="form-control"
                  v-model.trim="carrier"
                />
                <span class="help-block">航空公司代码</span>
              </div>
            </div>
            <div class="row">
              <label class="control-label col-md-4"> 出发机场 </label>
              <div class="col-md-6">
                <input type="text" class="form-control" v-model.trim="dport" />
                <span class="help-block">机场三字代码 或 * （所有机场）</span>
              </div>
            </div>
            <div class="row">
              <label class="control-label col-md-4"> 到达机场 </label>
              <div class="col-md-6">
                <input type="text" class="form-control" v-model.trim="aport" />
                <span class="help-block">机场三字代码 或 * （所有机场）</span>
              </div>
            </div>
            <div class="row">
              <label class="control-label col-md-4"> 日期（必填） </label>
              <div class="col-md-6">
                <input type="text" class="form-control" v-model.trim="ddate" />
                <span class="help-block"
                  >格式：yyyy-MM-dd 例如：2019-12-31</span
                >
              </div>
            </div>
            <div class="row">
              <label class="control-label col-md-4"> 提醒 </label>
              <div class="col-md-6 text-danger">
                2019年4月1日起需提供黑屏流量后方可使用<br />
              </div>
            </div>
          </form>
        </div>
        <div class="modal-footer">
          <button
            type="button"
            class="btn btn-secondary me-2"
            data-bs-dismiss="modal"
          >
            关闭
          </button>
          <button type="button" class="btn btn-primary" @click.stop="ok()">
            确定
          </button>
        </div>
      </div>
    </div>
  </div>
</template>


<script>
import $ from "jquery";

export default {
  props: {
    nullable: {
      type: Boolean,
      default: true,
    },
    id: {
      type: String,
      default: "fdRequestModal",
    },
    departments: {
      type: Array,
    },
  },
  data() {
    return {
      resolve: "",
      reject: "",
      promise: "",

      carrier: "",
      dport: "",
      aport: "",
      ddate: "",

      myModal: null,
    };
  },
  methods: {
    ok: function () {
      this.hideModal();

      this.resolve({
        carrier: this.carrier,
        dport: this.dport,
        aport: this.aport,
        ddate: this.ddate
      });
    },
    reset: function () {
      this.carrier = "";
      this.dport = "";
      this.aport = "";
      this.ddate = "";
    },
    modal: function () {
      this.reset();
      this.showModal();

      this.promise = new Promise((resolve, reject) => {
        this.resolve = resolve;
        this.reject = reject;
      });
      return this.promise;
    },
    showModal: function () {
      this.getMyModal().show();
    },
    hideModal: function () {
      this.getMyModal().hide();
    },
    getMyModal: function () {
      if (this.myModal === null) {
        let myModalEl = $(this.$el).get(0);
        this.myModal = new bootstrap.Modal(myModalEl, {
          keyboard: true,
        });
      }

      return this.myModal;
    },
  },
};
</script>
